package com.jt.www.remote;

import config.FeignConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @ClassName DexClient
 * @Description 数据交换中心 远程调用
 * @Author yanglichao
 * @Date 2019/6/23
 * @Version 1.0
 **/
@Service
@FeignClient(value = "dex-svc", url = "${remote.dex_svc_url}",
        configuration = FeignConfiguration.class, fallback = DexClient.DefaultFallback.class)
public interface DexClient {

    @PostMapping(value = "{channel}/text/{company}/{version}/{seqNo}", consumes = {"*/*;charset=UTF-8"})
    ResponseEntity<String> text(@PathVariable("channel") String channel, @PathVariable("company") String company, @PathVariable("version") String version, @PathVariable("seqNo") String seqNo, @RequestBody String body) throws Exception;


    @Component
    class DefaultFallback implements DexClient {
        public static final Logger log = LoggerFactory.getLogger(DefaultFallback.class);

        @Override
        public ResponseEntity<String> text(String channel, String company, String version, String seqNo, String body) throws Exception {
            log.warn("{}-数据交换中心远程调用失败,[channel:{}],[company:{}],[version:{}],[seqNo:{}],[body:{}]", "text"
                    , channel, company, version, seqNo, body);
//            throw new BizException("数据交换中心 text 远程调用失败");
            return null;
        }
    }
}
